# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=kubectl-krew
pkgver=0.4.4
pkgrel=2
pkgdesc="Find and install kubectl plugins"
url="https://krew.sigs.k8s.io/"
arch="all !armhf !riscv64" # kubectl
license="Apache-2.0"
depends="kubectl"
makedepends="go"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/kubernetes-sigs/krew/archive/refs/tags/v$pkgver.tar.gz
	test-use-testing-tmpdir.patch
	"
builddir="$srcdir/krew-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	GOLDFLAGS="
	-X sigs.k8s.io/krew/internal/version.gitCommit=AlpineLinux
	-X sigs.k8s.io/krew/internal/version.gitTag=v$pkgver
	"
	go build -tags netgo -ldflags "$GOLDFLAGS" -o bin/$pkgname ./cmd/krew/main.go
}

check() {
	# uses github api and gets 403
	# shellcheck disable=2046
	KREW_BINARY="$builddir/bin/$pkgname" go test $(go list ./... | grep -Ev '(cmd/internal)')
}

package() {
	install -Dm755 bin/$pkgname "$pkgdir"/usr/bin/$pkgname
}

sha512sums="
888362c564500d3f9f00b3207f5d63ee6546f9da6c884736fa55d49e78b91d5085a518f69f41b156cc8dc13667846be98bc2459392ca3d970c89721b6f4b632b  kubectl-krew-0.4.4.tar.gz
797a0f1361d893289217569e09dd5564fe545eaf2f0b3dc40367c63cb124b8120c5600d190732ced7885a020ae56a9417b49bccb8bca2c87faf72bf3e1359a81  test-use-testing-tmpdir.patch
"
